package cn.tedu.medicalpath.order.controller;

import cn.tedu.medicalpath.base.response.JsonResult;
import cn.tedu.medicalpath.order.pojo.param.OrderSaveParam;
import cn.tedu.medicalpath.order.pojo.param.OrderQuery;
import cn.tedu.medicalpath.order.pojo.vo.OrderVO;
import cn.tedu.medicalpath.order.pojo.vo.PrescriptionOrderVO;
import cn.tedu.medicalpath.order.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "费用支付模块")
@RestController
@RequestMapping("/v1/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @ApiOperation("查询满足条件的订单")
    @GetMapping("/find")
    public JsonResult findOrders(OrderQuery orderQuery){
        log.debug("查询满足条件的订单，入参：{}", orderQuery);
        log.debug("查询满足条件的订单-orderCostService，入参：{}", orderQuery);
        List<OrderVO> orderVOList = orderService.findOrders(orderQuery);
        log.debug("查询满足条件的订单-orderCostService，入参：{}，出参：{}", orderQuery, orderVOList);
        log.debug("查询满足条件的订单，入参：{}，出参：{}", orderQuery, orderVOList);
        return JsonResult.success(orderVOList);
    }

    @ApiOperation("进行支付操作")
    @PostMapping("/pay")
    public JsonResult payOrder(@RequestBody OrderSaveParam orderSaveParam){
        log.debug("进行支付操作，入参：{}", orderSaveParam);
        log.debug("进行支付操作-orderCostService，入参：{}", orderSaveParam);
        orderService.payOrder(orderSaveParam);
        log.debug("进行支付操作-orderCostService-成功，入参：{}", orderSaveParam);
        log.debug("进行支付操作-成功，入参：{}", orderSaveParam);
        return JsonResult.success();
    }

    @ApiOperation("查询满足条件的处方定单和对应的药品信息")
    @GetMapping("/findPrescriptionOrders")
    public JsonResult findPrescriptionOrdersAndSubMedicines(OrderQuery orderQuery){
        log.debug("查询满足条件的处方定单和对应的药品信息，入参：{}", orderQuery);
        log.debug("查询满足条件的处方定单和对应的药品信息-orderCostService，入参：{}", orderQuery);
        List<PrescriptionOrderVO> orderVOList =
                orderService.findPrescriptionOrdersAndSubMedicines(orderQuery);
        log.debug("查询满足条件的处方定单和对应的药品信息-orderCostService-成功，入参：{}，出参：{}", orderQuery, orderVOList);
        log.debug("查询满足条件的处方定单和对应的药品信息，入参：{}，出参：{}", orderQuery, orderVOList);
        return JsonResult.success(orderVOList);
    }
}
